const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
    let data = event;
    console.log(data)
    try {
        return await db.collection('role').where({
            _id: data._id
        })
            .update({
                data: {
                    attDistance: data.attDistance,
                    aoe: data.aoe,
                    control: data.control,
                    skill: data.skill,
                    attribute: [
                        {
                            blood: data.blood_1,
                            armor: data.armor_1,
                            aspeed: data.aspeed_1,
                            min_attack: data.min_attack_1,
                            max_attack: data.max_attack_1
                        },
                        {
                            blood: data.blood_2,
                            armor: data.armor_2,
                            aspeed: data.aspeed_2,
                            min_attack: data.min_attack_2,
                            max_attack: data.max_attack_2
                        },
                        {
                            blood: data.blood_3,
                            armor: data.armor_3,
                            aspeed: data.aspeed_3,
                            min_attack: data.min_attack_3,
                            max_attack: data.max_attack_3
                        },
                    ]
                },
            })
    } catch (e) {
        console.error(e)
    }
}